<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hasKey</title>
</head>

<body>
    <script>
        const hasKey = (obj, keys) =>
            keys.length > 0 &&
            keys.every(key => {
                if (typeof obj !== 'object' || !obj.hasOwnProperty(key)) {
                    return false;
                }
                obj = obj[key];
                return true;
            });
        let obj = {
            a: 1,
            b: { c: 4 },
            'b.d': 5
        };
        console.log(hasKey(obj, ['a'])); // true
        console.log(hasKey(obj, ['b'])); // true
        console.log(hasKey(obj, ['b', 'c'])); // true
        console.log(hasKey(obj, ['b.d'])); // true
        console.log(hasKey(obj, ['d'])); // false
        console.log(hasKey(obj, ['c'])); // false
        console.log(hasKey(obj, ['b', 'f'])); // false
    </script>
</body>

</html>